@extends('layouts.system_common')
@section('content')
    <script type="text/javascript">
        var element = document.getElementById("system_tab_4");
        element.classList.add("tab_selected");
    </script>
    <div class="breadcrumbs_container">
        {{ Breadcrumbs::render('customer.size_exchange') }}
    </div>

    <div>
        <form>
            <div class="form-group row col-sm-8">
                <label for="inputPassword" class="col-sm-2 col-form-label">订单编号</label>
                <div class="col-sm-6">
                    <input class="form-control form-control-sm lyx_subscribe_date" name="order_id" type="text">
                </div>
                <div class="col-sm-3">
                    <button class="btn btn-primary button_normal">搜索</button>
                </div>
            </div>
        </form>

        <div class="row">
            <table class="table table-striped">
                <thead style="background-color: #007BFF;color: white">
                <tr>
                    <th scope="col">@lang('symessages.info.create_time')</th>
                    <th scope="col">@lang('symessages.info.order_code')</th>
                    <th scope="col">@lang('symessages.info.product_name')</th>
                    <th scope="col">@lang('symessages.info.color')</th>
                    <th scope="col">数量</th>
                    <th scope="col">@lang('symessages.info.size')</th>
                    <th scope="col">@lang('symessages.info.change_size')</th>
                    <th scope="col">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($list as $value)
                    <tr id="lyx_tbody_tr" data-info="{{json_encode(object_to_array($value),JSON_UNESCAPED_UNICODE)}}">
                        <td>{{$value->create_time}}</td>
                        <td>{{$value->order_id}}</td>
                        <td>{{$value->goods_name}}</td>
                        <td>{{$value->color}}</td>
                        <td>{{$value->goods_num}}</td>
                        <td>{{$value->size}}</td>
                        <td>
                            <select class="form-control lyx_select_size" name="goods_size">
                                <option value="">@lang('symessages.info.all_msg')</option>
                                @foreach ($value->model_info as $key=>$size)
                                    <option value="{{$size['goods_model_id']}}" data-size_name="{{$size['size_name']}}" data-color_name="{{$size['color_name']}}">{{$size['color_name'].'/'.$size['size_name']}}</option>
                                @endforeach
                            </select>
                        </td>
                        <td>
                            <button class="btn btn-primary button_normal lyx_change_goods_btn">更换</button>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
    <?php echo csrf_field(); ?>
    <script>

        $(function () {

            $(".lyx_change_goods_btn").on('click', function () {
                var that = $(this);
                postData(that);
            })

            function postData(that) {

                var info = that.parents('tr').data('info');
                var size_name = that.parents('tr').find('.lyx_select_size').find('option:selected').data('size_name');
                info.size_name = size_name;
                var model_id = that.parents('tr').find('.lyx_select_size').val();
                info.model_id = model_id;
                createOrder(info);
            }

            function createOrder(data) {

                var token = $('input[name="_token"]').val();

                hdAjax({
                    url: "{{url('customer/change_order')}}",
                    data: {
                        data:data,
                        _token:token
                    },
                    type: 'post',
                    success: function (retData) {
                        if (retData.code == 1001) {
                            successAlert('一次成功に成功する', 'home');
                        } else {
                            layuiTopMsg(retData.msg);
                        }
                    }
                })
            }
        })


    </script>

@endsection
